package com.ruoyi.web.controller;

import com.ruoyi.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ruoyi.common.sms.entity.YytActActivity;
import com.ruoyi.common.sms.service.YytActActivityService;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
* <p>
    *  前端控制器
    * </p>
*
* @author MrPing
* @since 2022-06-15
*/
@RestController
@RequestMapping("/activity")
public class YytActActivityController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 获取活动倒计时
     * @param actId
     * @return
     */
    @GetMapping("/getSpuCountDown")
    public ResponseResult getSpuCountDown(@RequestParam("actId") String actId){
        String key = "actEnd:" + actId + "";
        Long expire = stringRedisTemplate.opsForValue().getOperations().getExpire(key);
        System.out.println(expire);
        Map<String, Long> map = new HashMap<>();
        long countDay = expire / 86400;
        long countHour = expire % 86400 / 3600;
        long countDown = expire % 3600 / 60;
        long secondTime = expire % 60;
        map.put("countDay", countDay);
        map.put("countHour", countHour);
        map.put("countDown", countDown);
        map.put("secondTime", secondTime);

        return ResponseResult.success(map);
    }

}
